<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_errand\Entity\ShusyErrandOrder;

/**
 * @OA\Schema(
 *   schema="ErrandOrder",
 *   type="object",
 *   description="ErrandOrder"
 * )
 */
class ErrandOrder extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_errand_order';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyErrandOrder) {
      $admin = FALSE;
      if (!empty($this->context)) {
        [$admin] = $this->context;
      }
      $value = [
        'admin' => $admin,
        /**
         * @OA\Property(
         *   property="id",
         *   type="integer",
         *   description="ID",
         * ),
         */
        'id' => (int) $this->entity->id,
        /**
         * @OA\Property(
         *   property="order",
         *   type="object",
         *   description="订单信息",
         *   ref="#/components/schemas/OrderPayment",
         * ),
         */
        'order' => OrderPayment::get($this->entity->store_order_id),
        /**
         * @OA\Property(
         *   property="errand",
         *   type="object",
         *   description="配送人员信息",
         *   ref="#/components/schemas/ErrandItem",
         * ),
         */
        'errand' => ErrandItem::get($this->entity->errand_id),
        /**
         * @OA\Property(
         *   property="status",
         *   type="integer",
         *   description="状态 0 待处理 1 配送中 2 已完成 3 关闭",
         * ),
         */
        'status' => (int) $this->entity->status,
      ];
      $this->merge($value);
    }
  }
}
